package com.jason.learn.springcloud.accountservice.controller;

import com.jason.learn.springcloud.accountservice.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/accountChange")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/addAmount")
    public boolean addAmount(Long accountId, BigDecimal amount){
        return accountService.addMoney(accountId,amount);
    }

    @RequestMapping("/reduceAmount")
    public boolean reduceAmount(Long accountId, BigDecimal amount){
        return accountService.addMoney(accountId,amount.negate());
    }

    @RequestMapping("/createAccount")
    public boolean createAccount(Long accountId,BigDecimal amount) {
        return accountService.createAccount(accountId,amount);
    }
}
